local skel = fk.CreateSkill {
  name = "emo__zhuimie",
}

Fk:loadTranslationTable{
  ["emo__zhuimie"] = "追灭",
  [":emo__zhuimie"] = "出牌阶段限一次，你可以选择一名其他角色，令你观看其或其观看你手牌，观看者可以弃置其中含有花色的手牌（每花色限一张）对另一方造成1点火焰伤害，然后另一方可以将至多X张手牌当等量张【杀】对观看者使用（X为观看者此时体力值）。",

  ["#emo__zhuimie"] = "追灭：你可以选择一名其他角色，令你观看其手牌，或令其观看你手牌",
  ["emo__zhuimie_me"] = "我看目标",
  ["emo__zhuimie_to"] = "目标看我",
  ["#emo__zhuimie-discard"] = "追灭：你可以弃置一张[ %arg ]手牌，对 %dest 造成1点火焰伤害",
  ["#emo__zhuimie-slash"] = "追灭：你可以将一张手牌当【杀】对 %dest 使用（剩余%arg次！）",
}


skel:addEffect("active", {
  anim_type = "offensive",
  prompt = "#emo__zhuimie",
  interaction = function(self, player)
    local all_choices = { "emo__zhuimie_me", "emo__zhuimie_to" }
    local choices = {}
    if table.find(Fk:currentRoom().alive_players, function (p)
      return p ~= player and not p:isKongcheng()
    end) then
      table.insert(choices, "emo__zhuimie_me")
    end
    if not player:isKongcheng() then
      table.insert(choices, "emo__zhuimie_to")
    end
    if #choices == 0 then return end
    return UI.ComboBox { choices = choices, all_choices = all_choices }
  end,
  card_num = 0,
  target_num = 1,
  target_filter = function (self, player, to_select, selected)
    if to_select:isKongcheng() and player:isKongcheng() then return end
    return #selected == 0
  end,
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryPhase)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local from = effect.from
    local to = effect.tos[1]
    local choice = self.interaction.data
    if choice == nil then return end
    if choice == "emo__zhuimie_to" then
      from, to = to, from
    end
    if to:isKongcheng() or from.dead then return end
    room:askToViewCardsAndChoice(from, {
      cards = to:getCardIds("h"), skill_name = skel.name
    })
    local suits = {}
    for _, id in ipairs(to:getCardIds("h")) do
      table.insertIfNeed(suits, Fk:getCardById(id):getSuitString())
    end
    while #suits > 0 and not from.dead and not to.dead do
      local pattern = ".|.|".. table.concat(suits, ",") .. "|hand"
      local arg = table.concat(table.map(suits, function (s) return Fk:translate("log_"..s) end), " ,")
      local discard = room:askToDiscard(from, {
        pattern = pattern, include_equip = false, max_num = 1, min_num = 1, cancelable = true, skill_name = skel.name, skip = true,
        prompt = "#emo__zhuimie-discard::" .. to.id .. ":" .. arg
      })
      if #discard == 0 then break end
      local suit = Fk:getCardById(discard[1]):getSuitString()
      table.removeOne(suits, suit)
      room:throwCard(discard, skel.name, from, from)
      room:doIndicate(from, {to})
      room:damage { from = from, to = to, damage = 1, skillName = skel.name, damageType = fk.FireDamage }
    end
    local limit = from.hp
    for i = 1, limit do
      if to.dead or from.dead or to:isKongcheng() then break end
      local cards = table.filter(to:getCardIds("h"), function (id)
        local slash = Fk:cloneCard("slash")
        slash.skillName = skel.name
        slash:addSubcard(id)
        return not to:isProhibited(from, slash) and not to:prohibitUse(slash)
      end)
      if #cards == 0 then break end
      local chosen = room:askToCards(to, {
        pattern = tostring(Exppattern{ id = cards }), min_num = 1, max_num = 1, cancelable = true, skill_name = skel.name,
        prompt = "#emo__zhuimie-slash::" .. from.id .. ":" .. (limit - i + 1)
      })
      if #chosen == 0 then break end
      room:useVirtualCard("slash", chosen, to, from, skel.name, true)
    end
  end,
})



return skel
